using System;
using System.Linq;
using System.Data.Objects;
using System.Data.Objects.DataClasses;
using System.ComponentModel;
using System.Runtime.Serialization;
using System.Collections.Generic;

[assembly: EdmSchemaAttribute()]
#region EDM Relationship Metadata


#endregion

namespace Acme.Sales.EFDAL
{
	#region AuditModifer

	/// <summary>
	/// This object holds the modifer information for audits on an ObjectContext
	/// </summary>
	public class AuditModifer
	{
		/// <summary>
		/// Creates a new instance of the AuditModifer object
		/// </summary>
		/// <param name="modifier"></param>
		public AuditModifer(string modifier)
		{
			this.Modifer = modifier;
		}

		/// <summary>
		/// The modifier string used for auditing
		/// </summary>
		public string Modifer { get; internal set; }
	}

	#endregion

	/// <summary>
	/// There are no comments for SalesEntities in the schema.
	/// </summary>
	public partial class SalesEntities : System.Data.Objects.ObjectContext
	{
		/// <summary>
		/// The audit modifier used to mark database edits
		/// </summary>
		protected AuditModifer _auditModifer = new AuditModifer(null);

		/// <summary>
		/// Initializes a new SalesEntities object using the connection string found in the 'SalesEntities' section of the application configuration file.
		/// </summary>
		public SalesEntities() :
			base("name=SalesEntities", "SalesEntities")
		{
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new SalesEntities object with an audit modifier.
		/// </summary>
		public SalesEntities(AuditModifer auditModifer) :
			base("name=SalesEntities", "SalesEntities")
		{
			_auditModifer = auditModifer;
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new SalesEntities object.
		/// </summary>
		public SalesEntities(string connectionString) :
			base(connectionString, "SalesEntities")
		{
			this.OnContextCreated();
		}

		/// <summary>
		/// Initialize a new SalesEntities object.
		/// </summary>
		public SalesEntities(System.Data.EntityClient.EntityConnection connection) :
			base(connection, "SalesEntities")
		{
			this.OnContextCreated();
		}

		partial void OnContextCreated();

		/// <summary>
		/// There are no comments for Customer in the schema.
		/// </summary>
		public System.Data.Objects.ObjectSet<Customer> Customer
		{
			get
			{
				if ((this._customer == null))
				{
					this._customer = base.CreateObjectSet<Customer>("Customer");
				}
				return this._customer;
			}
		}

		/// <summary>
		/// The internal reference variable for the 'Customer' object set
		/// </summary>
		protected System.Data.Objects.ObjectSet<Customer> _customer;

		#region AddItem Methods

		/// <summary>
		/// Adds an object of type 'Customer' to the object context.
		/// </summary>
		/// <param name="entity">The entity to add</param>
		public virtual void AddItem(Customer entity)
		{
			entity.CreatedBy = _auditModifer.Modifer;
			entity.ModifiedBy = _auditModifer.Modifer;
			base.AddObject("Customer", entity);
		}

		/// <summary>
		/// Adds an object to the object context.
		/// </summary>
		[Obsolete("This method signature is no longer used. Use one of the overloaded signatures", true)]
		[System.ComponentModel.EditorBrowsable(EditorBrowsableState.Never)]
		public new void AddObject(string entitySetName, object entity)
		{
			throw new Exception("This method signature is no longer used. Use one of the overloaded signatures");
		}

		#endregion

	}

	/// <summary>
	/// Extension methods for this library
	/// </summary>
	public static class Extensions
	{
		/// <summary>
		/// A map for all entity types in this library
		/// </summary>
		public enum TableMappingConstants
		{
			/// <summary>
			/// A mapping for the the Customer entity
			/// </summary>
			Customer,
		}

		#region Include Extension Methods

		/// <summary>
		/// Specifies the related objects to include in the query results.
		/// </summary>
		/// <param name="item"></param>
		/// <param name="entity">The related entity type to include</param>
		public static ObjectQuery<Customer> Include(this ObjectQuery<Customer> item, TableMappingConstants entity)
		{
			return item.Include(GetEntityMap(entity));
		}

		#endregion

		private static string GetEntityMap(TableMappingConstants entity)
		{
			switch (entity)
			{
				case TableMappingConstants.Customer: return "Customer";
				default: throw new Exception("Unknown entity type: " + entity.ToString());
			}
		}

	}

	/// <summary>
	/// The base class for all entity objects
	/// </summary>
	public abstract class NHEntityObject : EntityObject
	{
		/// <summary>
		/// Get the validation rule violations
		/// </summary>
		/// <returns></returns>
		public virtual IEnumerable<IRuleViolation> GetRuleViolations()
		{
			List<IRuleViolation> retval = new List<IRuleViolation>();
			return retval;
		}

		/// <summary>
		/// Determines if all of the validation rules have been met
		/// </summary>
		/// <returns></returns>
		public virtual bool IsValid()
		{
			return (GetRuleViolations().Count() == 0);
		}

		/// <summary>
		/// Test another entity object for equivalence against the current instance
		/// </summary>
		public abstract bool IsEquivalent(NHEntityObject item);

	}

}
